Search Results

Search found 8557 results on 343 pages for 'infinite loop'.

Page 115/343 | < Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >

  • Switch/Case statements in C++

    - by vgoklani
    Regarding the switch/case statement in the C++ code below: "Case 1" is obviously false, so how/why does it enter the do-while loop? #include <iostream> using namespace std; int main() { int test = 4; switch(test) { case 1: do { case 2: test++; case 3: test++; case 4: cout << "How did I get inside the do-while loop?" << endl; break; case 5: test++; } while(test > 0); cout << test << endl; } }

    Read the article

  • Is modifying a file without writing a new file possible in c++?

    - by Phenom
    Let's say I have a text file that is 100 lines long. I want to only change what is in the 50th line. One way to do it is open the file for input and open a new file for output. Use a for-loop to read in the first half of the file line by line and write to the second file line by line, then write what I want to change, and then write out the second half using a for-loop again. Finally, I rename the new file to overwrite the original file. Is there another way besides this? A way to modify the contents in the middle of a file without touching the rest of the file and without writing everything out again? If there is, then what's the code to do it?

    Read the article

  • What is the role of `while`-loops in computation expressions in F#?

    - by MizardX
    If you define a While method of the builder-object, you can use while-loops in your computation expressions. The signature of the While method is: member b.While (predicate:unit->bool, body:M<'a>) : M<'a> For comparison, the signature of the For method is: member b.For (items:seq<'a>, body:unit->M<'a>) : M<'a> You should notice that, in the While-method, the body is a simple type, and not a function as in the For method. You can embed some other statements, like let and function-calls inside your computation-expressions, but those can impossibly execute in a while-loop more than once. builder { while foo() do printfn "step" yield bar() } Why is the while-loop not executed more than once, but merely repeated? Why the significant difference from for-loops? Better yet, is there some intended strategy for using while-loops in computation-expressions?

    Read the article

  • Generate switch cases in php from an array?

    - by mopsyd
    Is it possible to generate the cases for a switch in php using an array? Something like: $x=array( 0 => 'foo', 1 => 'bar', 2 => 'foobar' ); $y='foobar' switch($y) { foreach($x as $i) { case $x: print 'Variable $y tripped switch: '.$i.'<br>'; break; } } I would like to be able to pull the case values from a database and loop through them with a while() loop.

    Read the article

  • Getting data from the next row in Oracle cursor

    - by Chaotic_one
    Hi, I'm building nested tree and I need to get data for the next row in cursor, using Oracle. And I still need current row, so looping forward is not a solution. Example: OPEN emp_cv FOR sql_stmt; LOOP FETCH emp_cv INTO v_rcod,v_rname,v_level; EXIT WHEN emp_cv%NOTFOUND; /*here lies the code for getting v_next_level*/ if v_next_level > v_level then /*code here*/ elsif v_next_level < v_level then /*code here*/ else /*code here*/ end if; END LOOP; CLOSE emp_cv;

    Read the article

  • c++ - what is faster ?

    - by VaioIsBorn
    If we have the following 2 snippets of code in c++ that do the same task: int a, b=somenumber; while(b > 0) { a = b % 3; b /= 3; } or int b=somenumber; while(b > 0) { int a=b%3; b /= 3; } I don't know much about computer architecture/c++ design, but i think that the first code is faster because it declares the integer a at the beginning and just uses it in the while-loop, and in the second code the integer a is being declared everytime the while-loop starts over. Can some one help me with this, am i correct or what and why ?

    Read the article

  • Opengl ES and texcoord

    - by viraptor
    Hi, I've got some code which I would like to translate into Opengl ES. I'm not experienced with it however, so here it goes. The original code does a loop like this: glBegin(GL_TRIANGLES); for(i=0; i<num_triangles; i++) { glNormal(...); glTexCoord2f(...); glVerted3fv(...); glTexCoord2f(...); glVerted3fv(...); glTexCoord2f(...); glVerted3fv(...); } glEnd(); So that's ok - I can change the vertex handling for each triangle in the loop, into the standard: glEnableClientState (GL_VERTEX_ARRAY); glVertexPointer (3, GL_SOMETHING, 0, verts); glDrawArrays (GL_TRIANGLES, 0, 3); But how do I add the texcoord setting into this example?

    Read the article

  • Fractional Calculator in Java

    - by user2888881
    I am trying to create a fractional calculator in Java with inputs of mixed fractions, proper fractions, improper fractions or integers. It should include the four basic operators as well. The program should be set up as a loop where it is continuous until the user types "quit". I have coded the beginning loop but have no idea where to go from there. Please help, I am a beginner and would really appreciate it. Thank you again. This is what I have so far: import java.util.*; public class FractionCalculator { private static Scanner input; public static void main(String[] args) { input = new Scanner(System.in); String x = "quit"; System.out.println("Enter a fraction"); while (true) { String y = input.next(); if (y.equals(x)) { break; } } } }

    Read the article

  • EXECUTE IMMEDIATE

    - by user578332
    Hi. I want to create table like this: create table ttt ( col1 varchar2(2), col2 varchar2(2), col3 varchar2(2), col4 varchar2(2), col5 varchar2(2) ); with this procedure, but it does not work. May you help me? declare str varchar2(200); i int; begin for i in 1 .. 5 loop begin str:=’str’||i||”; end; end loop; execute immediate ‘create table t1 (“str” varchar2(2) )’; end; / Thanks in advance.

    Read the article

  • PHP 1-liner each() with mysql_fetch_assoc()

    - by MVC You Know Me
    Hey All. Trying to create a 1-liner to loop through a mysql result set. Example: $sql = "SELECT uid, role FROM usr WHERE uid = '$this-uid'"; $r = db::q($sql); if($r-rows()) { $q = mysql_fetch_assoc($r-result); while(list($k, $v) = each($q)) { // would like to omit line above and consolidate here $_SESSION['usr'][$k] = $this->$k = $v; } } problem is that consolidating while loop like so: while(list($k, $v) = each(mysql_fetch_assoc($r-result)) returns an error a la each() not getting object or array, even though of course it is. I think the problem is a casting issue, but it does not seem you can do: each( (array) mysql_fetch_assoc($r-result)) Any ideas? I like to code as tersely as possible, and having "$q = mysql_fetch_assoc($r-result)" everywhere will annoy me, does already. Keep posted... Thanks!

    Read the article

  • How to iterate over numerically named object properties

    - by Scott Schluer
    So I have a horribly designed class that I can't change that has properties like this: object.Color1 object.Color2 object.Color3 etc... How can I iterate through those with a for loop. In other words, something like this: for (int i = 0; i <= 40; i++) { string PropertyName = "Color" + i; if (object.PropertyName != "") { // do something } } Obviously this code wouldn't work but it gives you an idea of what I'm after. I have to do some processing on each property and I don't want to repeat my code 40 times. :) A loop would be perfect, I'm just not sure how to create the name of the property on the fly.

    Read the article

  • looping and arrays

    - by user1838418
    Hi I'm trying to construct a loop to execute 16 states of the 8 4 2 1 code in (C++) while( condition) { double Bubble[16], Bubble1[16]; Bubble[0] = ( a-2 - (b-2) ) + ( c-2 - (d-2)); // represents 0000 Bubble[1] = ( a-2 - (b-2) ) + ( c-2 - (d+2)); // represents 0001 Bubble[2] = ( a-2 - (b-2) ) + ( c+2 - (d-2)); // represents 0010 Bubble[3] = ( a-2 - (b-2) ) + ( c+2 - (d+2)); //represents 0011 ....... Bubble[15] =(a+2 - (b+2) ) + ( c+2 - (d+2)); //represents 1111 } Is there an easy way of coding using for loops? instead of writing bubble[] every time? 0 stands for -2 and 1 stands for +2. So I have 4 variables and each one need to be incremented and/or decremented. Can this be done using for loop? Appreciate your help

    Read the article

  • trigger execution against condition satisfaction

    - by maheshasoni
    I have created this trigger which should give a error, whenever the value of new rctmemenrolno of table-receipts1 is matched with the memenrolno of table- memmast, but it is giving error in both condition(it is matched or not matched). kindly help me. CREATE OR REPLACE TRIGGER HDD_CABLE.trg_rctenrolno before insert ON HDD_CABLE.RECEIPTS1 for each row declare v_enrolno varchar2(9); cursor c1 is select memenrolno from memmast; begin open c1; fetch c1 into v_enrolno; LOOP If :new.rctmemenrolno<>v_enrolno then raise_application_error(-20186,'PLEASE ENTER CORRECT ENROLLMENT NO'); close c1; end if; END LOOP; end;

    Read the article

  • trigger execution against condition satisfaction

    - by maheshasoni
    I have created this trigger which should give a error, whenever the value of new rctmemenrolno of table-receipts1 is matched with the memenrolno of table- memmast, but it is giving error in both condition(it is matched or not matched). kindly help me. CREATE OR REPLACE TRIGGER HDD_CABLE.trg_rctenrolno before insert ON HDD_CABLE.RECEIPTS1 for each row declare v_enrolno varchar2(9); cursor c1 is select memenrolno from memmast; begin open c1; fetch c1 into v_enrolno; LOOP If :new.rctmemenrolno<>v_enrolno then raise_application_error(-20186,'PLEASE ENTER CORRECT ENROLLMENT NO'); close c1; end if; END LOOP; end;

    Read the article

  • 2 or more FOR loops in command shell merging fileA line1 with fileB line1, &c.

    - by rfransix
    Hi, i'm trying to build an ldif import file. I have 2 files, one with the DN and another with the employeeNumber, they match up line for line. Here's the code that does not work: @echo on ::Set BATCH Input Directory set batchdir=e:\Meta ::Set the input file containing the server list set infile=%batchdir%\DDNs3 set infile2=%batchdir%\DDNs4 ::If exists, we remove output file Rm DDNs3.ldif ::For loop below process each line in the input list. FOR /F "tokens=* delims=" %%i IN (%infile%) do ( FOR /F "tokens=* delims=" %%k IN (%infile2%) do ( Echo dn: %%i Echo changetype: modify Echo replace: employeeNumber Echo employeeNumber: %%k ) ) DDNs3.ldif I've tried several variations, including: ::For loop below process each line in the input list. FOR /F "tokens=* delims=" %%i IN (%infile%) do ( Echo dn: %%i Echo changetype: modify Echo replace: employeeNumber FOR /F "tokens=* delims=" %%k IN (%infile2%) do ( Echo employeeNumber: %%k echo. ) ) DDNs3.ldif

    Read the article

  • Have main thread wait for a boost thread complete a task (but not finish).

    - by JAKE6459
    I have found plenty on making one thread wait for another to finish executing before continuing, but that is not what I wanted to do. I am not very familiar with using any multi-threading apis but right now I'm trying to learn boost. My situation is that I am using my main thread (the starting one from int main()) to create an instance of a class that is in charge of interacting with the main GUI. A class function is then called that creates a boost thread which in turn creates the GUI and runs the message pump. The thing I want to do is when my main thread calls the classes member function to create the GUI, I don't want that function to return until I tell it to from the newly created thread. This way my main thread can't continue and call more functions from the GUI class that interact with the GUI thread until that thread has completed GUI creation and entered the message loop. I think I may be able to figure it out if it was multiple boost thread objects interacting with each other, but when it is the main thread (non-boost object) interacting with a boost thread object, I get lost. Eventually I want a loop in my main thread to call a class function (among other tasks) to check if the user as entered any new input into the GUI (buy any changes detected by the message loop being updated into a struct and changing a bool to tell the main thread in the class function a change has occurred). Any suggestions for any of this would be greatly appreciated. This is the member function called by the main thread. int ANNGUI::CreateGUI() { GUIMain = new Main(); GUIThread = new boost::thread(boost::bind(&Main::MainThreadFunc, GUIMain)); return 0; }; This is the boost thread starting function. void Main::MainThreadFunc() { ANNVariables = new GUIVariables; WndProc = new WindowProcedure; ANNWindowsClass = new WindowsClass(ANNVariables, WndProc); ANNWindow = new MainWindow(ANNVariables); GUIMessagePump = new MessagePump; ANNWindow-ShowWindows(); while(true) { GUIMessagePump-ProcessMessage(); } }; BTW, everything compiles fine and when I run it, it works I just put a sleep() in the main thread so I can play with the GUI a little.

    Read the article

  • Why is i++++++++i valid in python?

    - by SysAdmin
    I "accidentally" came across this weird but valid syntax i=3 print i+++i #outputs 6 print i+++++i #outputs 6 print i+-+i #outputs 0 print i+--+i #outputs 6 (for every even no: of minus symbol, it outputs 6 else 0, why?) Does this do anything useful? Update (Don't take it the wrong way..I love python): One of Python's principle says There should be one-- and preferably only one --obvious way to do it. It seems there are infinite ways to do i+1

    Read the article

  • Can a thread call wait() on two locks at once in Java (6)

    - by Dr. Monkey
    I've just been messing around with threads in Java to get my head around them (it seems like the best way to do so) and now understand what's going on with synchronize, wait() and notify(). I'm curious about whether there's a way to wait() on two resources at once. I think the following won't quite do what I'm thinking of: synchronized(token1) { synchronized(token2) { token1.wait(); token2.wait(); //won't run until token1 is returned System.out.println("I got both tokens back"); } } In this (very contrived) case token2 will be held until token1 is returned, then token1 will be held until token2 is returned. The goal is to release both token1 and token2, then resume when both are available (note that moving the token1.wait() outside the inner synchronized loop is not what I'm getting at). A loop checking whether both are available might be more appropriate to achieve this behaviour (would this be getting near the idea of double-check locking?), but would use up extra resources - I'm not after a definitive solution since this is just to satisfy my curiosity.

    Read the article

  • deleting and reusing a temp table in a stored precedures

    - by Sheagorath
    Hi I need to SELECT INTO a temp table multiple times with a loop but I just can't do it, because after the table created( in SELECT into you can't simply drop the table at the end of the loop because you can't delete a table and create it again in the same batch. so how can I delete a table in a stored procedure and create it again? here is a snippet of where I am actualy using the temp table which is supposed to be a pivoting algorithm: WHILE @offset<@NumDays BEGIN SELECT bg.*, j.ID, j.time, j.Status INTO #TEMP1 FROM #TEMP2 AS bg left outer join PersonSchedule j on bg.PersonID = j.PersonID and bg.TimeSlotDateTime = j.TimeSlotDateTime and j.TimeSlotDateTime = @StartDate + @offset DROP TABLE #TEMP2; SELECT * INTO #TEMP2 FROM #TEMP1 DROP TABLE #TEMP1 SET @offset = @offset + 1 END

    Read the article

  • Scanner class is skipping lines

    - by user2403304
    I'm new to programing and I'm having a problem with my scanner class. This code is in a loop and when the loop comes around the second, third whatever time I have it set to it skips the first title input. I need help please why is it skipping my title scanner input in the beginning? System.out.println("Title:"); list[i].title=keyboard.nextLine(); System.out.println("Author:"); list[i].author=keyboard.nextLine(); System.out.println("Album:"); list[i].album=keyboard.nextLine(); System.out.println("Filename:"); list[i].filename=keyboard.nextLine();

    Read the article

  • Vertical circular motion : time(x/y) versus velocity equation

    - by adeeti
    Hi, I wanted to simulate the following through animation : A ball starts with a certain velocity at the bottom most point of a vertical circular loop and keeps rolling in it until its velocity permits. For this, I wanted to find velocity/x/y vs. time equation. For e.g. if the ball had mass : 5Kg, radius of the circular loop = 10m, and initial velocity of the ball is 200 m/s, what will its velocity and (x,y) position be after 5 seconds? thanks.

    Read the article

  • How to do a random-and-unique generator?

    - by javaLearner.java
    I already wrote a random generator which take arguments a and b, where a is minimun and b is maximum value, like this randomGenerator(int a, int b) What I want to do next is: Using a loop, then generate unique number from a to b. Example: I want to have 8 unique numbers, int a = 1; int b = 10; int value; If I do the loop, there is a high % that same number will appear more than once. Any idea how to do it? My own way is: while(int i <= 8){ randomGenerator(a,b); // if value is not in array, then insert into array } I am stuck at the comment part. Is there any way to check if a variable is exists in an array?

    Read the article

  • between syntax, are there any equal function

    - by gcc
    /* char **mainp=malloc(sizeof(char *)*2); mainp[0]=malloc(sizeof(char)*300); mainp[1]=malloc(sizeof(char )*300); */ *I have some input about propositional calculus *After calculating some math funtion-removing paranthesis-changing"&" with ","-replacing "|" with"," I have >> (1) P,-Q,Q,-R is stored in mainp[0] R,A,P,B,F is stored in mainp[1] *My question is: Between comma , I have want to compare two pointer array. If there is any equal two or more functions(Q,-R is function representation) ,function which you will show me how to write must return int. According to example (1),function will return 1 (I expect like that) /*I have som thought://which function should I have use:*/ in for loop if( strspn(mainp[0][i])==1 ) increment d; continue; or in for loop srtcmp(mainp[0][i],mainp[1]);

    Read the article

< Previous Page | 111 112 113 114 115 116 117 118 119 120 121 122  | Next Page >