If condition and for loop statement, while, do: While, switch syntax

Source: Internet
Author: User

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&LT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.