Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Uitdaging: Else-instructie | Introductie tot Conditionele Instructies
C++ Conditionele Uitspraken

bookUitdaging: Else-instructie

else.h

else.h

copy
12345678
if (condition) { // Code to be executed if the condition is true } else { // Code to be executed if the condition is false }
main.cpp

main.cpp

copy
12345678910111213
#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } std::cout << "X is not greater than 10" << std::endl; }
main.cpp

main.cpp

copy
123456789101112131415
#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } else { std::cout << "X is not greater than 10" << std::endl; } }
Note
Opmerking
Taak

Swipe to start coding

Oplossing

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
single

single

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Suggested prompts:

Can you show me an example of how the if-else statement should be structured?

What happens if I add more conditions, like using else if?

Can you explain why the second std::cout was always executed before the fix?

close

bookUitdaging: Else-instructie

Veeg om het menu te tonen

else.h

else.h

copy
12345678
if (condition) { // Code to be executed if the condition is true } else { // Code to be executed if the condition is false }
main.cpp

main.cpp

copy
12345678910111213
#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } std::cout << "X is not greater than 10" << std::endl; }
main.cpp

main.cpp

copy
123456789101112131415
#include <iostream> int main() { int x = 5; if (x > 10) { std::cout << "X is greater than 10" << std::endl; } else { std::cout << "X is not greater than 10" << std::endl; } }
Note
Opmerking
Taak

Swipe to start coding

Oplossing

Switch to desktopSchakel over naar desktop voor praktijkervaringGa verder vanaf waar je bent met een van de onderstaande opties
Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4
single

single

some-alt