Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Create 10.w2.c
  • Loading branch information
amannamdev authored Oct 2, 2021
commit 7452be23f2eade9e79fbcd2b2a5e99c206eb8e62
58 changes: 58 additions & 0 deletions 10.w2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdbool.h>

#define SIZE 4

int main(void)
{
int prices[SIZE] = { 100, 200, 300, 400 };

bool isTrue = true;
bool isFalse = false;

printf("True: %d, False: %d\n", isTrue, isFalse);

printf(" 'While' Loop:\n");

int i = 0;

while(i < SIZE)
{
printf("%d\n", prices[i]);
i++;
}

printf(" 'For' Loop:\n");

for (int i = 0; i < SIZE; i++)
{
printf("%d\n", prices[i]);
}

printf("Second 'For' Loop:\n");

for (int i = 0; i < SIZE; i++)
{
printf("%d\n", prices[i]);
}

// Если использовать одну инструкцию в теле while, for, if, else
// то фигурные скобки можно не писать
printf("For Loop Short Form:\n");

for (int i = 0; i < SIZE; i++) printf("%d\n", prices[i]);

printf("Do-While Loop:\n");

// Разница с while в том, что здесь тело цикла
// выполняется как минимум один раз: сначала выполняется,
// затем идет проверка условия
int j = 0;

do {
printf("%d\n", prices[j]);
j++;
} while(j < SIZE); // обратить внимание на точку с запятой!

return 0;
}