搜尋此網誌

2025年7月23日星期三

Selecting the right while loop

while (condition){
    // Code to execute
}

do{
    // Code to execute
}while (condition);

The do...while loop is executed at least once.

negate: to stop something from having any effect

The exclamation mark ! is the logical NOT operator. It inverts a boolean value.

getline is a handy function in C++ for reading a whole line of text, especially when you're dealing with strings that might include spaces.

getline(cin, userInput); // reads full line including spaces

std::getline(std::cin, playerName);

using std::getline from the <string> header to read a full line of input into playerName

\n is a newline character used in C++.

do{
    // Code to execute
}while (choice != 3);

repeats until they select option 3

Microsoft Copilot

沒有留言:

發佈留言