Search Results

Search found 1698 results on 68 pages for 'loops'.

Page 19/68 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • add limited product to cart in android

    - by user1859172
    I have to develop one shopping cart app. Here i have to add the product only 5.otherwise have to display the message on alert dialog like 5 products only allowed. How can i develop this.please help me This is my code: ImageButton mImgAddCart = (ImageButton) findViewById(R.id.img_add); mImgAddCart.setOnClickListener(new OnClickListener() { public void onClick(View v) { // TODO Auto-generated method stub mTitle = txttitle.getText().toString(); mCost = text_cost_code.getText().toString(); mCost = mCost.replace("From ", ""); mTotal = txt_total.getText().toString(); mTotal = mTotal.replace("From ", ""); mQty = edit_qty_code.getText().toString(); if (Constants.mItem_Detail.size() <= 0) { HashMap<String, String> mTempObj = new HashMap<String, String>(); mTempObj.put(KEY_TITLE, mTitle); mTempObj.put(KEY_QTY, mQty); mTempObj.put(KEY_COST, mCost); mTempObj.put(KEY_TOTAL, mTotal); Constants.mItem_Detail.add(mTempObj); } else { for (int i = 0; i < Constants.mItem_Detail.size(); i++) { if (Constants.mItem_Detail.get(i).get(KEY_TITLE) .equals(mTitle)) { Constants.mItem_Detail.remove(i); break; } else { } } HashMap<String, String> mTempObj = new HashMap<String, String>(); mTempObj.put(KEY_TITLE, mTitle); mTempObj.put(KEY_QTY, mQty); mTempObj.put(KEY_COST, mCost); mTempObj.put(KEY_TOTAL, mTotal); Constants.mItem_Detail.add(mTempObj); } AlertDialog.Builder alertdialog = new AlertDialog.Builder( Small.this); alertdialog.setTitle(getResources() .getString(R.string.app_name)); alertdialog.setMessage("Add in ViewCart"); alertdialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub finish(); } }); alertdialog.show(); } }); How can i set the condition for this.please give me one idea.

    Read the article

  • Objective C "do - while" question

    - by Rob
    The example for one of the exercises in the book I am reading shows the following code: #import <Foundation/Foundation.h> int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; int input, reverse, numberOfDigits; reverse = 0; numberOfDigits = 0; NSLog (@"Please input a multi-digit number:"); scanf ("%i", &input); if ( input < 0 ) { input = -input; NSLog (@"Minus"); } do { reverse = reverse * 10 + input % 10; numberOfDigits++; } while (input /= 10); do { switch ( reverse % 10 ) { case 0: NSLog (@"Zero"); break; case 1: NSLog (@"One"); break; case 2: NSLog (@"Two"); break; case 3: NSLog (@"Three"); break; case 4: NSLog (@"Four"); break; case 5: NSLog (@"Five"); break; case 6: NSLog (@"Six"); break; case 7: NSLog (@"Seven"); break; case 8: NSLog (@"Eight"); break; case 9: NSLog (@"Nine"); break; } numberOfDigits--; } while (reverse /= 10); while (numberOfDigits--) { NSLog (@"Zero"); } [pool drain]; return 0; } My question is this, the while statement shows (input /= 10) which, if I understand this correctly basically means (input = input / 10). Now, if that is true, why doesn't the loop just run continuously? I mean, even if you were to divide 0 by 10 then that would still extract a number. If the user was to input "50607", it would first cut off the "7", then the "0", and so on and so on, but why does it exit the loop after removing the "5". Wouldn't the response after the "5" be the same as the "0" between the 5 and the 6 to the program?

    Read the article

  • Rails: How to name and create unique divs within a loop?

    - by sscirrus
    I have a view with a div that is looped many times. Each of the created divs need to have a unique ID so I can access them specifically (at the moment, all my divs have the same ID specified in html so whenever I try to access a specific div it just finds the first one). This is the version that I currently have (multiple 'rowBox'es are not discernible). <% @customers.each do |customer| %> <div id="customer" class="rowBox"> ... </div> <% end %> I would like to be able to do something like: <% @customers.each do |customer| %> <div id="box<%=customer.id%>"> ... </div> <% end %> This doesn't seem to work. Any ideas on how to accomplish this?

    Read the article

  • Another php array looping question

    - by Dan
    Been battling with this one for what seems, like forever. I have an array: $url_array It contains this info: Array ( [ppp] => Array ( [0] => stdClass Object ( [id] => 46660 [entity_id] => 0 [redirect_url] => http://www.google.com [type] => Image ) [1] => stdClass Object ( [id] => 52662 [entity_id] => 0 [pixel_redirect_url] => http://www.yahoo.com [type] => Image ) [2] => stdClass Object ( [id] => 53877 [entity_id] => 0 [redirect_url] => http://www.msn.com [pixel_type] => Image ) ) [total_count] => 3 ) I need to loop through it, and do things to each variable. I can get this to work: foreach ($piggies_array as $key => $value) { $id = $value[0]->id; $redirect_url = $value[0]->redirect_url; } Not unsurprisingly, it's only echoing the first value of those variables, but no matter what I try I cannot get it to loop through: $value->redirect_url; $value=>redirect_url; I would appreciate any help.

    Read the article

  • Update Params in Python During Infinite Loop

    - by python Dude
    Hello, I was hoping to get some help on a question. I have an infinite loop that I need run and I need to update a set of variables (x in this case) at random times from the command-line. Is there any way to do this? For example: x = 0 while True: x = x + 1 if x < 30: do something and I need to update x's value from the command-line periodically

    Read the article

  • How can I loop through each of the days of a given week in Ruby?

    - by Angela
    I am defining monday and friday using the following: @monday = Date.today.at_beginning_of_week @friday = 5.days.since(@monday) But I actually need, for any given day, to loop through Monday, Tuesday, Wednesday and take that date and put the output into a column. <th>Monday</th> <th>Tuesday</th> etcetera A given row, for example, would be: <tr><td>value(monday)</td><td>value(tuesday)</td><td>value(wednesday)</td></tr> This is where value is a method that takes args date. What's the cleanest way to do this? Thanks.

    Read the article

  • How to parse a string (by a "new" markup) with R ?

    - by Tal Galili
    Hi all, I want to use R to do string parsing that (I think) is like a simplistic HTML parsing. For example, let's say we have the following two variables: Seq <- "GCCTCGATAGCTCAGTTGGGAGAGCGTACGACTGAAGATCGTAAGGtCACCAGTTCGATCCTGGTTCGGGGCA" Str <- ">>>>>>>..>>>>........<<<<.>>>>>.......<<<<<.....>>>>>.......<<<<<<<<<<<<." Say that I want to parse "Seq" According to "Str", by using the legend here Seq: GCCTCGATAGCTCAGTTGGGAGAGCGTACGACTGAAGATCGTAAGGtCACCAGTTCGATCCTGGTTCGGGGCA Str: >>>>>>>..>>>>........<<<<.>>>>>.......<<<<<.....>>>>>.......<<<<<<<<<<<<. | | | | | | | || | +-----+ +--------------+ +---------------+ +---------------++-----+ | Stem 1 Stem 2 Stem 3 | | | +----------------------------------------------------------------+ Stem 0 Assume that we always have 4 stems (0 to 3), but that the length of letters before and after each of them can very. The output should be something like the following list structure: list( "Stem 0 opening" = "GCCTCGA", "before Stem 1" = "TA", "Stem 1" = list(opening = "GCTC", inside = "AGTTGGGA", closing = "GAGC" ), "between Stem 1 and 2" = "G", "Stem 2" = list(opening = "TACGA", inside = "CTGAAGA", closing = "TCGTA" ), "between Stem 2 and 3" = "AGGtC", "Stem 3" = list(opening = "ACCAG", inside = "TTCGATC", closing = "CTGGT" ), "After Stem 3" = "", "Stem 0 closing" = "TCGGGGC" ) I don't have any experience with programming a parser, and would like advices as to what strategy to use when programming something like this (and any recommended R commands to use). What I was thinking of is to first get rid of the "Stem 0", then go through the inner string with a recursive function (let's call it "seperate.stem") that each time will split the string into: 1. before stem 2. opening stem 3. inside stem 4. closing stem 5. after stem Where the "after stem" will then be recursively entered into the same function ("seperate.stem") The thing is that I am not sure how to try and do this coding without using a loop. Any advices will be most welcomed.

    Read the article

  • C# loop - break vs. continue

    - by Terrapin
    In a C# (feel free to answer for other languages) loop, what's the difference between break and continue as a means to leave the structure of the loop, and go to the next iteration? Example: foreach (DataRow row in myTable.Rows){ if (someConditionEvalsToTrue) { break; //what's the difference between this and continue ? //continue; }}

    Read the article

  • JQuery going through a set of UL and dynamically set ids incremently on each one

    - by Calibre2010
    I have an unordered list which contains serveral items called 'oListItems' the UL has a class but no id. The class OuteroListItems contains many of oListitems oList.AppendFormat("<ul class='OuteroListItems'>"); oList.AppendFormat("<li>"); oList.AppendFormat("<ul class='oListItems'>"); oList.AppendFormat("<li>" + s.sName + "</li>"); oList.AppendFormat("<li>" + s.eName + "</li>"); oList.AppendFormat("<li>" + s.SDate + "</li>"); oList.AppendFormat("<li>" + s.EDate + "</li>"); oList.AppendFormat("</ul>"); oList.AppendFormat("</li>"); oList.AppendFormat("</ul>"); I want for each .oListItem class that gets retrieved, add dynamically an id to it. var o = $(".oListItem"); $.each(o, function (){ var f = $(this).attr("id", 'listItem' + i); i++; }); wasent sure on the approach, this is what I have so far?

    Read the article

  • Codeigniter view file looping query

    - by user2505513
    Right, I'm unsure about how to code my view file to generate following query results WITHOUT compromising the principles of mvc. Query in model: SELECT * FROM events GROUP BY country, area ORDER BY country, area View: <?php if (isset($query)):?> <?php foreach ($query as $row):?> <h2><?=$row->country?></h2> <h3><?=$row->area?></h3> <?php endforeach;?> <?php endif;?> I want the results to display: England North South West - utilising the GROUP BY parameter As opposed to: England North England South England West Has anybody any advice as to how to achieve this?

    Read the article

  • Skipping a line and reading another line in shell script while loop

    - by parameswar
    i have a code which reads a file line by line using a while loop. Inside the while loop, i have certain conditions. Is there a way using which i can skip the current line and read the next line based upon the condition ? Let me be precise: while read Line do //some sample conditions a=$Line if [ "a" == "b" ] //i want to go to the next line from this point. done < **inputfile** Any help would be appreciated.

    Read the article

  • Problem with loop MATLAB

    - by Jessy
    no time scores 1 10 123 2 11 22 3 12 22 4 50 55 5 60 22 6 70 66 . . . . . . n n n Above a the content of my txt file (thousand of lines). 1st column - number of samples 2nd column - time (from beginning to end ->accumulated) 3rd column - scores I wanted to create a new file which will be the total of every three sample of the scores divided by the time difference of the same sample. e.g. (123+22+22)/ (12-10) = 167/2 = 83.5 (55+22+66)/(70-50) = 143/20 = 7.15 new txt file 83.5 7.15 . . . n so far I have this code: fid=fopen('data.txt') data = textscan(fid,'%*d %d %d') time = (data{1}) score= (data{2}) for sample=1:length(score) ..... // I'm stucked here .. end ....

    Read the article

  • Check the cumulative status of onLoadInit in a for statement

    - by jonobr1
    In a setup like this is it possible to check the cumulative status of all onLoadInit? for(var i:Number = 0; i < limit; i++) { var mcLoader:MovieClipLoader = new MovieClipLoader(); var mclListener:Object = new Object(); mclListener.onLoadInit = function(mc:MovieClip) { trace(i + " is finished loading!"); } mcLoader.addListener(mclListener); mcLoader.loadClip(some_image_path, someMovieClip); } Initially I was thinking that I could pass an array of Boolean's, but I'm not really sure where to add that checkpoint, because a flash frame doesn't keep looping. Would I have to add it to an onEnterFrame()?

    Read the article

  • ForEach loop in Mathematica.

    - by dreeves
    I'd like something like this: ForEach[i_, {1,2,3}, Print[i] ] Or, more generally, to destructure arbitrary stuff in the list you're looping over, like: ForEach[{i_, j_}, {{1,10}, {2,20}, {3,30}}, Print[i*j] ] (Meta-question: is that a good way to call a ForEach loop, with the first argument a pattern like that?) ADDED: Some answerers have rightly pointed out that usually you want to use Map or other purely functional constructs and eschew a non-functional programming style where you use side effects. I agree! But here's an example where I think this ForEach construct is supremely useful: Say I have a list of options (rules) that pair symbols with expressions, like attrVals = {a -> 7, b -> 8, c -> 9} Now I want to make a hash table where I do the obvious mapping of those symbols to those numbers. I don't think there's a cleaner way to do that than ForEach[a_ -> v_, attrVals, h[a] = v] ADDED: I just realized that to do ForEach properly, it should support Break[] and Continue[]. I'm not sure how to implement that. Perhaps it will need to somehow be implemented in terms of For, While, or Do since those are the only loop constructs that support Break[] and Continue[]. If anyone interested in this wants to ask about that as a separate question, please do!

    Read the article

  • C++ Loop - Need variable to accumulate sum

    - by user1780064
    I'm writing a program to ask the user to enter a value between 5 and 21 (inclusive). If the number entered is not in this range, it prints, "Please try again". If the number is within the range, I need to take that number, and print the sum of all the numbers from 1 to the value entered. So if the user entered "7", the sum would be "28". I successfully wrote the first loop, in the case of the number not being within the range, but cannot figure out how to run the second loop- whether to use a while, do-while, or for loop. Please advise. #include <iostream> int main () { int uservalue; int count; int sum; //Prompt user for input do { cout << "Enter a value from 5 to 21: "; cin >> uservalue; if (uservalue < 5 || uservalue > 21) cout << "Value out of range. Try again..." << endl; } while (uservalue < 5 || uservalue > 21); cout << endl; //Loop to accumulate sum for (count = 1, count < uservalue, count++;) { sum = uservalue + count; if (uservalue <= 5 || uservalue <= 21) cout << the sum is " << sum << endl; } return 0; }

    Read the article

  • Change class of parent div if radio input checked

    - by xxstevenxo
    I've been searching and searching google for answers to my question but have been unsuccessful so far. I'm hoping one of you guys could give me some assistance. I have 10 divs with the class name "dividend" holding a table with the classname/id of "container" then two smaller tables inside that. Within the container table at the bottom is a hidden radio button with the name "page1". I wrote an onClcick for the container table so the user can select the whole table instead of the radio button, but not I'm trying to change the style of the selected container so the users know they have selected it. I have tried a few different methods and I'm able to change the style to the new class by just writing document.getElementById('container').className = 'selected'; But because all 10 divs share the same name it will only change the style of the first element it finds. So I tried writing this loop to check if there are any selected radios in the document then to change the else name the style as the default. I'm sure its something stupid but I'm pretty stumped atm.. Any help would be appreciated. Thanks. selected = function () { var divs = document.getElementByTagName('DIV'), div, tbl, rad, stat, i; for (i = 0; i < divs.length; i++) { div = divs.id; if (div == 'dividend') { tbl = div.getElementById('container'); rad = tbl.getElementByTagName('INPUT'); if (rad.checked = true) { tbl.className = 'selected'; } } } };

    Read the article

  • Pulling $_GET data and creating multidimensional array using loop

    - by Chris J
    I'm creating a checkout for customers and the data about what's in their cart is being sent to a page (for just now) via $_GET. I want to extract that data and then populate a multidimensional array with it using a loop. Here's how I'm naming the data: $itemCount = $_GET['itemCount']; $i = 1; while ($i <= $itemCount) { ${'item_name_'.$i} = $_GET["item_name_{$i}"]; ${'item_quantity_'.$i} = $_GET["item_quantity_{$i}"]; ${'item_price_'.$i} = $_GET["item_price_{$i}"]; //echo "<br />Name: " .${'item_name_'.$i}. " - Quantity: " .${'item_quantity_'.$i}. " - Price: ".${'item_price_'.$i}; $i++; } From here I'd like to create a multidimensional array like such: Array ( [Item_1] => Array ( [item_name] => Shoe [item_quantity] => 2 [item_price] => 40.00 ) [Item_2] => Array ( [item_name] => Bag [item_quantity] => 1 [item_price] => 60.00 ) [Item_3] => Array ( [item_name] => Parrot [item_quantity] => 4 [item_price] => 90.00 ) . . . ) What I'd like to know is if there is a way I can create this array in the existing while loop? I'm aware of being able to add data to an array like $data = [] after delacring an empty array but the actual syntax eludes me. Maybe I'm completely off the right track and there is a better way of doing it? Thanks

    Read the article

  • Substituting variables in a loop?

    - by jksl
    I am trying to write a loop in R but I think the nomenclature is not correct as it does not create the new objects, here is a simplified example of what I am trying to do: for i in (1:8) { List_i <-List colsToGrab_i <-grep(predefinedRegex_i, colnames(List_i$table)) List_i$table <- List_i$table[,predefinedRegex_i] } I have created 'predefinedRegex'es 1:8 which the grep should use to search The loop creates an object called "List_i" and then fails to find "predefinedRegex_i". I have tried putting quotes around the "i" and $ in front of the i but these do not work. Any help much appreciated. Thank you.

    Read the article

  • Retrieve array key passed on value PHP

    - by Doodle
    I have the following array $group= array( [0] => 'apple', [1] => 'orange', [2] => 'gorilla' ); I run the array group through an for each function and when the loop hits values of gorilla I want it to spit out the index of gorilla foreach( $group as $key){ if ($key==gorilla){ echo //<------ the index of gorilla } }

    Read the article

  • Looping through covariates in regression using R

    - by Kyle Peyton
    I'm trying to run 96 regressions and save the results as 96 different objects. To complicate things, I want the subscript on one of the covariates in the model to also change 96 times. I've almost solved the problem but I've unfortunately hit a wall. The code so far is, for(i in 1:96){ assign(paste("z.out", i,sep=""), lm(rMonExp_EGM~ TE_i+ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+ Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies)) } This works on the object creation side (e.g. I have z.out1 - z.out96) but I can't seem to get the subscript on the covariate to change as well. I have 96 variables called TE_1, TE_2 ... TE_96 in the dataset. As such, the subscript on TE_, the "i" needs to change to correspond to each of the objects I create. That is, z.out1 should hold the results from this model: z.out1 <- lm(rMonExp_EGM~ TE_1 + Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+ Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies) And z.out96 should be: z.out96 <- lm(rMonExp_EGM~ TE_96+ Month2+Month3+Month4+Month5+Month6+Month7+Month8+Month9+ Month10+Month11+Month12+Yrs_minus_2004 + as.factor(LGA),data=Pokies) Hopefully this makes sense. I'm grateful for any tips/advice. cheers, kyle

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >