Question

In: Computer Science

2. What loops run while in a true condition?

 
In your own words write an example of a loop that you perform in your day to day life
 
Sample answer - If(“want to make money” –eq “true”){
 
Goto-work
 
Now answer the following questions
 
2. What loops run while in a true condition?
 
3. What loop runs while in a false condition?
 
4. What PowerShell loop sets the variable, the condition, and the iteration of the variable all in one?
 
5. Describe in your own words what each loop is used for.

Solutions

Expert Solution

 

2.

“While” loop

Explanation

The while loop will execute while in a true condition.

3.

“Do until”

Explanation

The “do until” loop will execute while in a false condition.

4.

The ‘for’ loop is the loop that sets the variable, the condition, and the iteration all in one statement.

5.

The ‘foreach’ loop is one that is especially powerful the reason is that it iterates through a collection of objects. You can then work with each object in the collection individually.

 


Related Solutions

C++ . It should all be in one code and using WHILE loops 2. Write a...
C++ . It should all be in one code and using WHILE loops 2. Write a piece of code that asks the user for a number and adds up the even numbers from 1 to that entered number. 3. Write a piece of code that asks the user for 2 numbers and adds up the numbers between and including the numbers. 4. Write another piece of code that asks the user for a random file name and adds all of...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In...
Code in Python. You can only use while loops NOT for loops. Program 1: cost_living In 2020 the average cost of living/month (excluding housing) for a family of 4 in Pittsburgh was $3850 per month. Write a program to print the first year in which the cost of living/month is over $4450 given that it will rise at a rate of 2.1% per year. (Note:  this program requires no input). Program 2: discount A discount store is having a sale where...
Explain in word what “no arbitrage” condition mean and why this condition may not hold true...
Explain in word what “no arbitrage” condition mean and why this condition may not hold true in reality? Bring at least 2 reasons for it.
how would i change the for loops to while loops in the code below #include<stdio.h> #include<stdlib.h>...
how would i change the for loops to while loops in the code below #include<stdio.h> #include<stdlib.h> int main() { int seed; // Taking seed value as input from the user printf("Enter a seed value (0 to quit): \n"); scanf("%d", &seed); // Running the loop until user enters 0 to quit // count array will count frequency of 0 , 1 , 2 ,3 int count[4]; for (int i = 0; i < 4; i++) count[i] = 0; while (seed !=...
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a...
Python Exercises = Sentinel Values and While Loops #Exercise 1 #Write a while loop with a sentinel value #This while loop ends when the user enters a 1, the sentinel value #Assign the number 8 to a variable which will serve as the sentinel value #Condition: while variable is not equal to 1 #Action: display the number assigned to the variable #Use an input statement (no prompt) to ask the user for a number and assign this number to the...
C++ Code while loops. 1. Ask for file name and open file. 2. Do a priming...
C++ Code while loops. 1. Ask for file name and open file. 2. Do a priming read and make a while loop that A) Reads in numbers B) Sums them up. C) Counts how many there are. D) Prints "With 10 numbers, the average is blank.." every 10 numbers. So with every 10 numbers read in print the average. 3. After the loop calculate average of all numbers and print it. So for example once the file is open the...
The purpose of this exercise is to give you experience in writing condition-controlled loops. Create a...
The purpose of this exercise is to give you experience in writing condition-controlled loops. Create a code in Python that will print monthly loan amortization schedule given the loan amount (P), APR i.e. Annual Percentage Rate (r=APR in %/12), loan terms in number of months (n). Please use these formulas: Monthly Payment (A) = P * ((r * (1 + r)**n)/(((1+r)**n)-1))            Monthly Interest Pmt (mIP)= r * Total Remaining Balance Monthly Principal Pmt (mPP) = A –...
1. The correct mean for Condition One is _______ while the correct mean for Condition Two is ______:
Condition 1 Scores Condition 2 Scores 1 8 2 3 3 4 3 10 4 2 4 8 4 7 5 7 2 8 6 9 2 10 5 10 Column Mean Column Median Column Mode Standard Deviation Column Range 1. The correct mean for Condition One is _______ while the correct mean for Condition Two is ______: A. 3.50 and 8.00 B. 3.42 and 7.17 C. 4.00 and 8.00 D. 1.51 and 2.76 E. 7.17 and 3.42 2. The...
Given the following pre-condition and program segment, what is the post-condition for y? // Pre-condition: -2...
Given the following pre-condition and program segment, what is the post-condition for y? // Pre-condition: -2 <= x < 4 y = 2*x*x - x +3
This assignment will acquaint you with the use of while loops and boolean expressions. You will...
This assignment will acquaint you with the use of while loops and boolean expressions. You will create a program that acts as a score keeper of a racquet ball game between two players. The program will continually ask the user who the winner of every point is as the game is played. It will maintain the scores and declare the match is over, using these rules: (1) A game is over when a. one of the players wins 7 points...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT