| Last Part | Next part |
|---|---|
| <- #03 Escape Sequences and better print instructions | #05 First coding challanges -> |
if (argument) { } else { }
In this example, I ask the program, if x (5) is smaller than y (8). If x is smaller than y, then print "x is smaller than y". Else print "x is bigger or equal y".
And if I change y to 4, than it will give me this output
But what if you want to separate the bigger and equal print, then change your code to this
The else if (argument) if the same as the normal if instruction, but built in, in a if-Loop.
Note: The break; statement means, that it will jump out of the loop, otherwise it would completely run through.
He will read the number of the variable and go through the loop. In case the number is 2, then he prints, what's standing inside of it. But if the number doesn't attach to anything, than he will enter the default block. In my case, x is 5
But when I change x to 2 and rerun, then it will output this
for (create variable + initialization; as long as true; add 1 to variable) { }
I have really problems to explain this one ^^ Please try to understand this with the information, I gave you.
A while-Loop is this
This is the syntax: while(boolean) { }
As long as the boolean is true, the loop will continue to run. When it's false, then it will stop.
Fun Fact:
You can create a infinit-Loop by entering for the boolean a true
That's it for the loop tutorial. Thanks for reading!
Support this project by upvote this post and commenting ^^ (and resteem)
| Last Part | Next part |
|---|---|
| <- #03 Escape Sequences and better print instructions | #05 First coding challanges -> |