do-while

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

混江龙づ霸主 提交于 2019-11-26 14:30:44
问题 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

Are “while(true)” loops so bad? [closed]

依然范特西╮ 提交于 2019-11-26 14:06:35
I've been programming in Java for several years now, but I just recently returned to school to get a formal degree. I was quite surprised to learn that, on my last assignment, I lost points for using a loop like the one below. do{ //get some input. //if the input meets my conditions, break; //Otherwise ask again. } while(true) Now for my test I'm just scanning for some console input, but I was told that this kind of loop is discouraged because using break is akin to goto , we just don't do it. I understand fully the pitfalls of goto and its Java cousin break:label , and I have the good sense

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

≡放荡痞女 提交于 2019-11-26 10:06:47
问题 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! 回答1: It is considered acceptable practice to

Emulating a do-while loop in Bash

左心房为你撑大大i 提交于 2019-11-26 07:07:04
问题 What is the best way to emulate a do-while loop in Bash? I could check for the condition before entering the while loop, and then continue re-checking the condition in the loop, but that\'s duplicated code. Is there a cleaner way? Pseudo code of my script: while [ current_time <= $cutoff ]; do check_if_file_present #do other stuff done This doesn\'t perform check_if_file_present if launched after the $cutoff time, and a do-while would. 回答1: Two simple solutions: Execute your code once before

Do while loop in SQL Server 2008

别来无恙 提交于 2019-11-26 06:16:31
问题 Is there any method for implement do while loop in SQL server 2008? 回答1: 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

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

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-26 05:56:37
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . 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

Are “while(true)” loops so bad? [closed]

爷,独闯天下 提交于 2019-11-26 03:48:31
问题 I\'ve been programming in Java for several years now, but I just recently returned to school to get a formal degree. I was quite surprised to learn that, on my last assignment, I lost points for using a loop like the one below. do{ //get some input. //if the input meets my conditions, break; //Otherwise ask again. } while(true) Now for my test I\'m just scanning for some console input, but I was told that this kind of loop is discouraged because using break is akin to goto , we just don\'t do

Emulate a do-while loop in Python?

扶醉桌前 提交于 2019-11-26 01:24:52
问题 I need to emulate a do-while loop in a Python program. Unfortunately, the following straightforward code does not work: list_of_ints = [ 1, 2, 3 ] iterator = list_of_ints.__iter__() element = None while True: if element: print element try: element = iterator.next() except StopIteration: break print \"done\" Instead of \"1,2,3,done\", it prints the following output: [stdout:]1 [stdout:]2 [stdout:]3 None[\'Traceback (most recent call last): \', \' File \"test_python.py\", line 8, in <module> s