do-while

Do .. While loop in C#?

删除回忆录丶 提交于 2019-11-28 02:27:39
问题 How do I write a Do .. While loop in C#? (Edit: I am a VB.NET programmer trying to make the move to C#, so I do have experience with .NET / VB syntax. Thanks!) 回答1: The general form is: do { // Body } while (condition); Where condition is some expression of type bool . Personally I rarely write do/while loops - for , foreach and straight while loops are much more common in my experience. The latter is: while (condition) { // body } The difference between while and do...while is that in the

Re-prompt user after invalid input in Java

China☆狼群 提交于 2019-11-27 22:49:46
问题 I'm writing this program in java where I need to re-prompt the user after an invalid input. I came to a solution only to discover that if the user enters another invalid input after the re-prompt then it continues. Can someone please show me a better solution to this? I'll show you what I had anyway: System.out.println("What is your age?\n"); age = userInput.nextInt(); if((age > 120) || (age < 1)) {//error message System.out.println("ERROR Please enter a valid age"); System.out.println("");

how does do{} while(0) work in macro?

跟風遠走 提交于 2019-11-27 09:07:47
Though this topic has been discussed many times in this forum and all other forums, still I have doubts. Please help. How does the do{} while(0) in macro work in Linux kernel? For example, #define preempt_disable() do { } while (0) How does it disable preempt? #define might_resched() do { } while (0) How does it reschedule? Similarly I have seen macros for mutex locks and other also. How does this help? I understand for following problem but not for the examples above. #define foo(x) do { do something } while(0) Edit: What about the following code for rt_mutex_lock ? /** * rt_mutex_lock - lock

Why use a “do while” loop? [closed]

断了今生、忘了曾经 提交于 2019-11-27 06:46:47
问题 I've never understood why using a do while loops is necessary. I understand what they do, Which is to execute the code that the while loop contains without checking if the condition is true first. But isn't the below code: do{ document.write("ok"); } while(x == "10"); The exact same as: document.write("ok"); while(x == "10"){ document.write("ok"); } Maybe I'm being very stupid and missing something obvious out but I don't see the benefit of using do while over my above example. 回答1: Your

Reading key/value parameters from a file into a shell script

别来无恙 提交于 2019-11-27 05:37:23
I've got my script working almost. The goal of this is to take defined values from a file and then populate these valeus in a shell script at runtime. Please take a look at what i have here... The first file: ab.sh #!/bin/bash USER_TYPE=$1 #IDENTIFY USER TYPE TYPE1,TYPE2,TYPE3,TYPE4 USERNAME=$2 PERMISSION_TYPE=$3 #IDENTIFY PERMISSION TYPE SELECT,UPDATE,DELETE,INSERT TARGET_USER=$4 TARGET_TABLE=$5 if [ $USER_TYPE == 'TYPE1' ] then cat Parameters.conf |while read USERNAME do sqlplus / as sysdba << E00 CREATE USER ${USERNAME} DEFAULT TABLESPACE USERS TEMPORARY TABLESPACE TEMP ACCOUNT UNLOCK;

What are some better ways to avoid the do-while(0); hack in C++?

▼魔方 西西 提交于 2019-11-27 02:34:35
When the code flow is like this: if(check()) { ... ... if(check()) { ... ... if(check()) { ... ... } } } I have generally seen this work around to avoid the above messy code flow: do { if(!check()) break; ... ... if(!check()) break; ... ... if(!check()) break; ... ... } while(0); What are some better ways that avoid this work-around/hack so that it becomes a higher-level (industry level) code? Any suggestions which are out of the box are welcome! It is considered acceptable practice to isolate these decisions in a function and use return s instead of break s. While all these checks correspond

do-while loop in R

放肆的年华 提交于 2019-11-27 00:50:09
问题 I was wondering about how to write do-while-style loop? I found this post: you can use repeat{} and check conditions whereever using if() and exit the loop with the "break" control word. I am not sure what it exactly means. Can someone please elaborate if you understand it and/or if you have a different solution? 回答1: Pretty self explanatory. repeat{ statements... if(condition){ break } } Or something like that I would think. To get the effect of the do while loop, simply check for your

Do while loop in SQL Server 2008

心不动则不痛 提交于 2019-11-26 18:21:58
Is there any method for implement do while loop in SQL server 2008? Pratik I am not sure about DO-WHILE IN MS SQL Server 2008 but you can change your WHILE loop logic, so as to USE like DO-WHILE loop. Examples are taken from here: http://blog.sqlauthority.com/2007/10/24/sql-server-simple-example-of-while-loop-with-continue-and-break-keywords/ Example of WHILE Loop DECLARE @intFlag INT SET @intFlag = 1 WHILE (@intFlag <=5) BEGIN PRINT @intFlag SET @intFlag = @intFlag + 1 END GO ResultSet: 1 2 3 4 5 Example of WHILE Loop with BREAK keyword DECLARE @intFlag INT SET @intFlag = 1 WHILE (@intFlag <

&#39;do…while&#39; vs. &#39;while&#39;

冷暖自知 提交于 2019-11-26 15:20:29
Possible Duplicates: While vs. Do While When should I use do-while instead of while loops? I've been programming for a while now (2 years work + 4.5 years degree + 1 year pre-college), and I've never used a do-while loop short of being forced to in the Introduction to Programming course. I have a growing feeling that I'm doing programming wrong if I never run into something so fundamental. Could it be that I just haven't run into the correct circumstances? What are some examples where it would be necessary to use a do-while instead of a while? (My schooling was almost all in C/C++ and my work

Test loops at the top or bottom? (while vs. do while) [closed]

为君一笑 提交于 2019-11-26 14:41:22
When I was taking CS in college (mid 80's), one of the ideas that was constantly repeated was to always write loops which test at the top (while...) rather than at the bottom (do ... while) of the loop. These notions were often backed up with references to studies which showed that loops which tested at the top were statistically much more likely to be correct than their bottom-testing counterparts. As a result, I almost always write loops which test at the top. I don't do it if it introduces extra complexity in the code, but that case seems rare. I notice that some programmers tend to almost