If statement
int score = 70;
if (Score < 20) {
NSLog (@ "failed");
}else if (score >= 60)
{
NSLog (@ "pass");
}
If the judgment condition exists in more than one case, judging whether a year is run year
int year;
printf ("Please enter a year:");
scanf ("%d", &year);
if (year%4 = = 0 && Year%!=0) | | year% 400 = = 0)
{
NSLog (@ "This is run Year"):
}else
{
NSLog (@ "This is not run year");
}
Classroom Exercises
For loop printing 1-200 numbers that cannot be divisible by 3
for (int i = 1; i <; i++)
{
if (i% 3! = 0) {
NSLog (@ "This number cannot be divisible by 3:%d", i);
}
}
To print a 99 multiplication table with a for loop
for (int i = 1; I <= 9; i++)
{
for (int j = 1; J <= I; j + +)
{
printf ("%d *%d =%d", I, J, I*j);
}
printf ("\ n");
}
While
int i = 0;
while (I < 10) {
NSLog (@ "I:%d", i);
i + +;
}
equals for loop
for (int i=0; i<10; i++) {
NSLog (@ "For i:%d", I);
}
Do While
i = 0;
do {
i + +;
NSLog (@ "do:i:%d", I);
}while (I<10);
Break
int num =0, j = 10;
while (J <= 100) {
if (j% 4 ==0) {
NSLog (@ "%d", j);
num++;
}
if (num = = 5) {
Break
}
i++;
}
while (J <= 100) {
if (j% 4 ==0) {
NSLog (@ "%d", j);
num++;
}
if (num = = 5) {
Continue
}
i++;
}
int score = 60;
Switch (score)
{
Case 40:
NSLog (@ "failed");
Break
Case 60:
NSLog (@ "pass");
Break
Case 90:
NSLog (@ "excellent");
Break
Default
NSLog (@ "no score");
Break
}
If condition and for loop statement, while, do: While, switch syntax