import std.stdio;string analyzeHoursOfSleep(int hours){if(!hours)return"You didn't sleep at all.";string msg ="";switch(hours){case1,2,3:
msg ~="You slept way too little! ";gotocase7;case4:..case6:
msg ~="Take a nap later to increase alertness. ";case7:
msg ~="Try to go back to sleep for a bit more. ";break;default:
msg ~="Good morning. Grab a cup of coffee. ";}return msg ~'\n';}void main(){
writeln(analyzeHoursOfSleep(3));
writeln(analyzeHoursOfSleep(6));
writeln(analyzeHoursOfSleep(7));
writeln(analyzeHoursOfSleep(13));int i =0;
L1:while(true){while(true){if(i ==3)break L1;
i++;break;}
writeln("Still not out of the loop!");}}/*
Output:
You slept way too little! Try to go back to sleep for a bit more.
Take a nap later to increase alertness. Try to go back to sleep for a bit more.
Try to go back to sleep for a bit more.
Good morning. Grab a cup of coffee.
Still not out of the loop!
Still not out of the loop!
Still not out of the loop!
*/

Using if allows you to make part of your code only execute if a certain condition is met.

if(condition that evaluates to true or false)
{
// code that is executed if condition is true
} else {
// code that is executed if condition is false
}

In fact, if the section of code that's inside the if or else is only one line long, you can omit the curly brackets.

if(condition1) do_this();
else if(condition2) do_that(); // only executed if condition1 is false, but
// condition2 is true
else do_the_other_thing(); // only executed if both condition1 and condition2 are false

The condition that goes inside of the parentheses in conditional statements such as if can be anything convertible to bool. That includes integral and floating-point types (true if nonzero, false if otherwise) and pointers (null is false, and dynamic arrays (always true).

A while loop will allow you to repeat a block of code as long as a certain condition is met. There are two forms of the while loop:

while(condition1) {
do_this();
}

and

do {
do_this();
} while(condition1)

The difference is, in the first example, if condition1 is false, do_this is never called, while in the second example it would be called once (the conditional check happens after the code is executed once).

This type of looping is the most complex, but it is also the one that gives a lot of control. It is defined in the same way as other C-like languages:

for(initialization; condition; counting expression) { ... }

The initialization expression is executed only once during the beginning. Then condition is checked to be true or false. If it is true, the code inside of the conditional block (inside of the brackets) is executed. After that execution, the counting expression is executed. Then, the condition is checked, and if it is true, the loop continues. For example:

for(int i=0; i <=5; i++){
write(i);}// output: 012345

You can even omit parts of what goes inside the parentheses of the for. These two are equivalent:

The break statement breaks out of the loop. Whenever the break statement is encountered, the loop is immediately exited. This statement can go inside of while, for, foreach, and switch blocks (you will learn about those later).

The continue statement causes a loop to restart at the beginning. Let's see, through code, exactly how this works. This code example counts to 7 but skips 5.