Question

Rewriting this For loop into a while loop: int32_t block_poweroff(void) { uint64_t ky1, fm1; uint64_t cs1;...

Rewriting this For loop into a while loop:

int32_t block_poweroff(void)
{
uint64_t ky1, fm1;
uint64_t cs1;
int64_t rt1;
for(int i = 0; i <BLOCK_MAX_TOTAL_FILES; i++){
block_close(i); //closing all files
}
BlockXferRegister regAfterPowerOff = block_io_bus(BLOCK_OP_POWOFF, 0);
unpack(regAfterPowerOff, &ky1, &fm1, &cs1, &rt1);
return rt1;
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Rewriting this For loop into a while loop:

int32_t block_poweroff(void)

{

uint64_t ky1, fm1;

uint64_t cs1;

int64_t rt1;

int i = 0;

while(i <BLOCK_MAX_TOTAL_FILES)

{

block_close(i); //closing all files

i++;

}

BlockXferRegister regAfterPowerOff = block_io_bus(BLOCK_OP_POWOFF, 0);

unpack(regAfterPowerOff, &ky1, &fm1, &cs1, &rt1);

return rt1;

}

Description:

• For converting for loop into while loop, you need to first initialize the variable. Then specify the while condition and loop statements followed by variable increment/decrement.

• Syntax of While loop:

initialization;

while(condition)

{

loop statements;

variable increment/decrement;

}

Add a comment
Know the answer?
Add Answer to:
Rewriting this For loop into a while loop: int32_t block_poweroff(void) { uint64_t ky1, fm1; uint64_t cs1;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Let's put this into action, in rewriting a while loop to a for loop, in the...

    Let's put this into action, in rewriting a while loop to a for loop, in the context of the provided function allnum (strlist), which takes a list of strings strlist, and returns the list of strings which are made up exclusively of digits (in the same order the strings occurred in the original). Note that the rewritten function should behave identically to the original, and the only changes you should make are to the while loop and associated variables, to...

  • computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int...

    computers. 1. How many times will this loop repeat? include <stdlib.h> #include <stdio.h> void main(void) int 10 for(= 0; i < 101) printf("d", 1); A. 10 times B. 1 time C. It will run forever D. 0 times 2. What will be the output of this program? #include <stdlib.h> #include <stdio.h> int main() int a = 100, b = 200, C = 300; if(!a >= 500) b = 300; C = 400; printf("%d, 8d, &d", a, b, c); return 0;...

  • Please answer both questions thank you. Rewrite the following for loop into a while loop: int...

    Please answer both questions thank you. Rewrite the following for loop into a while loop: int s S = 0; for (int i = 1; i <= 10; i++) { S += i; int s = 0; int i = while (i <= 10) S = + i; i++; } int s = 0; int i = 1; while (i <= 10) { s = s + i; i++; } int S = 0; int i = 1; while (i...

  • How do I write this code from while loop to for loop? (this is the whole...

    How do I write this code from while loop to for loop? (this is the whole code) NOTE: do not add any import other than: import java.util.ArrayList; import java.util.Collection;(collection not collections) import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.HashSet; code: public static int frequency(Collection values, int target) { var iter = values.iterator(); int app = 0; while (iter.hasNext()) { if(iter.next() == target) { app++; } } return app; } public static boolean isSorted(List list) { var iter = list.listIterator(); int...

  • in c++ language 1.Re-write the following for loop statement by using a while loop statement: int...

    in c++ language 1.Re-write the following for loop statement by using a while loop statement: int sum = 0; for(int i=0;i<=1000;i++){                 sum+=i; } 1 (b). Following is the main () function of a program. The program asks a user to enter 150 integers and print the largest integer user entered. int main() {    int score, highest;             //missing portion of the program             return 0;    } 1(c). Find the missing portion of the following code, so the...

  • Convert the following while loop into a for loop. int 1 - 50: int sum-07 while...

    Convert the following while loop into a for loop. int 1 - 50: int sum-07 while (sum < 1000) sum - sum + 1; Question 35 (2 points) Saved Given an int variable k that has already been declared, use a while loop to print a single line consisting of 80 dollar signs. Use no variables other than k. int sum = 0; for(int i = 100;sum < 10000;1-- sum = sum + i;

  • Creating a calculator for my CS1 class and my code was able to run but it...

    Creating a calculator for my CS1 class and my code was able to run but it crashes near the end. As far as I know, the error means that it's retrieving "null" from the variable but I haven't seen that kind of error from this kind of situation. I would appreciate any help. I'm just starting up in Java so I apologize if this is a silly question. Thank you! ``` ----jGRASP exec: java CS1Calculator ------------ Welcome to the CS1...

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • Programming language: C NOT c++ Problem 2 (20 points) Both the for loop and the do-while...

    Programming language: C NOT c++ Problem 2 (20 points) Both the for loop and the do-while loop can be transformed into a simple while loop. For each of the following examples a) and b), write equivalent code using a while loop instead. double rand_double)( double ret - (double)rand(); return ret/ (RAND MAX 1); int factorial (int n) int for i, ret =1; (i=2; i <= ret *= 1; n; i++) int sample_geometric_rv(double p)l double q return ret; int ne; do...

  • C++: Need help debugging my code I am writing this and using some other examples as reference code while rewriting it with my own understanding of the material but am having trouble making it finally...

    C++: Need help debugging my code I am writing this and using some other examples as reference code while rewriting it with my own understanding of the material but am having trouble making it finally compile. Below is a picture of the error messages. //main.cpp //Semester Project //Created by J---on 5/6/2019 #include <iostream> #include <fstream> #include <string> #include <sstream> #include <bits/stdc++.h> using namespace std; void instructions(); //displays program details and instructions void openFile(); void takeInput(int*); void switchBoard(int*); struct price {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT