increment

Bash Script - Variable Scope in Do-While loop

纵饮孤独 提交于 2019-12-02 08:52:19
问题 I have a do while loop where I am adding a variable to itself while read line do let variable=$variable+$someOtherVariable done return $variable When I echo the value of $variable I get no output ... Is this the correct way to add some value back to the variable itself (i.e. i = i+j) Also, in the context of bash scripting what is the scope in this case.. 回答1: The problem is that the variable is not visible outside of the scope (the assignment is not propagated outside the loop). The first way

How to insert if not exists, or increase if exists in SQLite?

China☆狼群 提交于 2019-12-02 08:36:10
I have the following table: CREATE TABLE 'Test' ('Id' INTEGER PRIMARY KEY NOT NULL, 'Val' INTEGER) If a given Id doesn't exist, I want to insert the Id with a default Val. But if it already exists, I want to increase the value of Val. I have this code: $data = array(':id'=>$id); $stmt = $db->prepare('INSERT INTO Test (Id, Val) Values(:id, 1);'); if(!$stmt->execute($data)){ $stmt = $db->prepare('UPDATE Test SET Val=Val+1 WHERE Id=:id'); $stmt->execute($data); } and it works, but I would want to do it with a single SQL statement. Can I? EDIT : From @Xikinho90's answer, my final code is $stmt =

Problem with chaining operator<< and operator++

做~自己de王妃 提交于 2019-12-02 08:10:35
问题 I'm learning C++ and I have this problem: #include <iostream> using namespace std; class test { public: test(){}; test(int i):var{i}{}; test& operator++(){++var; return this;} test operator++(int dummy){test tmp =*this;var++;return tmp;} friend ostream& operator<<(ostream&, const test&); private: int var; }; ostream& operator<<(ostream& o, const test& obj) { o<<obj.var; return o; } int main() { test obj{2}; cout << obj << endl; obj++; cout << obj << endl; cout << obj <<' '<< ++obj<<endl;

Incrementing number in file name when file exists

杀马特。学长 韩版系。学妹 提交于 2019-12-02 07:18:27
I am still very new to Python (3). I have a BUNCH of sensor data, but the download limit forces me to retrieve the data in chunks instead of all at once (each .zip file downloaded contains a folder of .csv files for each sensor's data during a given time period). Thus, I have dozens of large .csv files distributed among several folders that I would eventually like to concat/merge/append into one .csv file for each sensor's full data. To make things more complicated, .csv file names for each sensor are identical across the folders. I have developed the following code to rename and move the

Plus/minus incrementator in Jquery, how to generalize?

孤街浪徒 提交于 2019-12-02 06:29:21
I'm using this code <a id="minus" href="#">-</a> <span id="VALUE">0</span> <a id="plus" href="#">+</a> Javascript: $(function(){ var valueElement = $('#VALUE'); function incrementValue(e){ valueElement.text(Math.max(parseInt(valueElement.text()) + e.data.increment, 0)); return false; } $('#plus').bind('click', {increment: 1}, incrementValue); $('#minus').bind('click', {increment: -1}, incrementValue); }); to have a plus/minus incrementator of the filed named "VALUE". Now, i have a form using this containing 150 field like this... there's a way to generalize this code passing in some way to the

Problem with chaining operator<< and operator++

穿精又带淫゛_ 提交于 2019-12-02 06:19:39
I'm learning C++ and I have this problem: #include <iostream> using namespace std; class test { public: test(){}; test(int i):var{i}{}; test& operator++(){++var; return this;} test operator++(int dummy){test tmp =*this;var++;return tmp;} friend ostream& operator<<(ostream&, const test&); private: int var; }; ostream& operator<<(ostream& o, const test& obj) { o<<obj.var; return o; } int main() { test obj{2}; cout << obj << endl; obj++; cout << obj << endl; cout << obj <<' '<< ++obj<<endl; return 0; } the output i expected was: 2 3 3 4 instead i have: 2 3 4 4 if i replace the last increment +

CakePHP increment value

非 Y 不嫁゛ 提交于 2019-12-02 06:14:21
My problem looks as follows: I want to make a vote app where People can choose one or more Events(like Doodle). For this I have set up a function called vote. In the View you can choose the Events using checkboxes. The Models are Poll and Groupevent. A Poll has Many Groupevents. My Problem is when I call updateAll() , all values of the associated Groupevents are incremented. Here is my code: View: echo $this->Form->create('Poll', array('action' => 'vote')); for($i=0; $i<$count; $i++){ echo $this->Form->input('Groupevent.'.$i.'.votes', array('type'=>'checkbox', 'label'=>$this->Groupevent[

for loop without index declaration

£可爱£侵袭症+ 提交于 2019-12-02 05:25:29
So I declare a variable some where and initialize it. Now later on I need to use it to loop while its still positive so I need to decrement it. To me looping using a condition and a decrement calls for a for but for it we are missing the first part the initialization. But I don't need to initialize anything. So how do I go about that in a nice way. for (space = space; space > 0; space--)//my first way to do it but ide doesnt like it Second way: for (; space > 0; space--)//my friend recommended me this way but looks kind weird Are there more ways for me to have a loop with only condition and

Bash Script - Variable Scope in Do-While loop

百般思念 提交于 2019-12-02 04:23:32
I have a do while loop where I am adding a variable to itself while read line do let variable=$variable+$someOtherVariable done return $variable When I echo the value of $variable I get no output ... Is this the correct way to add some value back to the variable itself (i.e. i = i+j) Also, in the context of bash scripting what is the scope in this case.. The problem is that the variable is not visible outside of the scope (the assignment is not propagated outside the loop). The first way that comes to mind is to run the command in a subshell and forcing the loop to emit the variable: variable=

Incrementing a number in a div using Javascript

◇◆丶佛笑我妖孽 提交于 2019-12-02 04:17:20
问题 I'm very new to Javascript, so I assume this is a stupid mistake. function upvote() { var score = parseInt(document.getElementById('voteScore').innerHTML); score = score++; document.getElementById('voteScore').innerHTML = score; } The div named "voteScore" contains the number 46 only (no HTML or anything). I am attempting to grab the string, convert it to an int, increment it and put it back in the div. 回答1: score++ increments score , you don't need to assign it back to score . Either remove