Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
While loops in C are easy! ♾️
Play lesson

C tutorial for beginners ⚙️ - While loops in C are easy! ♾️

4.0 (0)
13 learners

What you'll learn

This course includes

  • 6.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#coding #programming #cprogramming // while loop = Continue some code WHILE the condition remains true // Condition must be true for us to enter while loop // ---------- EXAMPLE 2 ---------- char name[50] = ""; printf("Enter your name: "); fgets(name, sizeof(name), stdin); name[strlen(name) - 1] = '\0'; while (strlen(name) == 0) { printf("Name cannot be empty! Please enter your name: "); fgets(name, sizeof(name), stdin); name[strlen(name) - 1] = '\0'; } printf("Hello %s!", name); // ---------- EXAMPLE 3 ---------- bool isRunning = true; char response = '\0'; while(isRunning){ printf("You are playing a game\n"); printf("Would you like to continue? (Y = yes, N = no): "); scanf(" %c", &response); // remove \n from input buffer if(response != 'Y' && response != 'y'){ isRunning = false; } } printf("You exit the game"); return 0;

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere